//
//  ZMDiscoverArticleHeadViewCell.m
//  基本框架
//
//  Created by runone02 on 2018/7/5.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "ZMDiscoverArticleHeadViewCell.h"
#import "ZMDiscoverHeadModel.h"

@interface ZMDiscoverArticleHeadViewCell ()<SPPageMenuDelegate>

@end

@implementation ZMDiscoverArticleHeadViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [ZMColor whiteColor];
    }
    for (UIView *view in self.subviews) {
        if([view isKindOfClass:[UIScrollView class]]) {
            ((UIScrollView *)view).delaysContentTouches = NO; // Remove touch delay for iOS 7
            break;
        }
    }
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundView.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    return self;
}

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    if (!_pageMenu) {
        SPPageMenu *pageMenu = [SPPageMenu pageMenuWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70) trackerStyle:SPPageMenuTrackerStyleLineAttachment];
        pageMenu.permutationWay = SPPageMenuPermutationWayNotScrollEqualWidths;
        pageMenu.closeTrackerFollowingMode = YES;
        pageMenu.hideLine = YES;
        pageMenu.unSelectedItemTitleColor = [ZMColor appSupportColor];
        
        //传递数组默认选中第一个
        NSMutableArray *itemArr = [NSMutableArray array];
        for (id model in dataArray) {
            if ([model isKindOfClass:[ZMDiscoverHeadModel class]]) {
                [itemArr addObject:((ZMDiscoverHeadModel *)model).title];
            }
        }
        [pageMenu setItems:itemArr selectedItemIndex:0];
        
        for (int i =  0; i < dataArray.count; i ++) {
            id model = [dataArray safeObjectAtIndex:i];
            if ([model isKindOfClass:[ZMDiscoverHeadModel class]]) {
                ZMDiscoverHeadModel *headModel = model;
                [pageMenu setTitle:headModel.title image:IMAGE(headModel.img) imagePosition:SPItemImagePositionTop imageRatio:0.5 forItemIndex:i];
            }
        }
        pageMenu.showFuntionButton = NO;
        pageMenu.delegate = self;
        [self.contentView addSubview:pageMenu];
        self.pageMenu = pageMenu;
    }
}

- (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedAtIndex:(NSInteger)index{
    
    if (index == 0) {
        NSLog(@"点击了人气携手");
    }else if (index == 1){
        NSLog(@"点击了专题精选");
    }else{
        NSLog(@"点击了其他");
    }
}
@end
